package com.company.modeldesign;

public class TripleInOne {


    private int[] entity;

    int[] size ={-1,-1,-1};
    int stackSize;

    public TripleInOne(int stackSize) {
        this.stackSize = stackSize;
        entity = new int[stackSize * 3];
    }



    public void push(int stackNum, int value) {
        int stackPoint = size[stackNum];

        if (stackPoint==this.stackSize-1) {
            return;
        }

        int base = stackNum*stackSize; // 0 , 1  2  对应 开始位置  0，stackSize,2*stackSize
        //是否满栈

        size[stackNum]=stackPoint+1;
        entity[size[stackNum]+base]=value;
    }

    public int pop(int stackNum) {
        int stackPoint = size[stackNum];

        if (stackPoint==-1) {
            return -1;
        }

        int base = stackNum*stackSize; // 0 , 1  2  对应 开始位置  0，stackSize,2*stackSize
        int result = entity[base+stackPoint];
        size[stackNum]=stackPoint-1;
        return result;
    }

    public int peek(int stackNum) {
        int stackPoint = size[stackNum];
        if (stackPoint==-1) {
            return -1;
        }
        int base = stackNum*stackSize; // 0 , 1  2  对应 开始位置  0，stackSize,2*stackSize
        int result = entity[base+stackPoint];
        return result;
    }

    public boolean isEmpty(int stackNum) {
        return size[stackNum]==-1;
    }
}
